package com.suns.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;

@Controller
public class MyErrorController implements ErrorController {

    @RequestMapping("/error")
    public ModelAndView handle(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("errorCode", request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
        modelAndView.addObject("errorMessage", request.getAttribute(RequestDispatcher.ERROR_MESSAGE));
        modelAndView.setViewName("AllPageError");
        return modelAndView;
    }

}